<template>
  <div class="login-container">
    <el-form ref="form" :model="form" :rules="rules" class="login-form">
      <h2 class="title">管理员登录</h2>
      <el-form-item prop="username">
        <el-input v-model="form.username" placeholder="用户名" prefix-icon="el-icon-user"></el-input>
      </el-form-item>
      <el-form-item prop="password">
        <el-input v-model="form.password" placeholder="密码" type="password" prefix-icon="el-icon-lock"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="handleLogin" class="login-btn">登录</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
export default {
  data() {
    return {
      form: {
        username: '',
        password: ''
      },
      rules: {
        username: [
          { required: true, message: '请输入用户名', trigger: 'blur' }
        ],
        password: [
          { required: true, message: '请输入密码', trigger: 'blur' }
        ]
      }
    }
  },
  methods: {
    handleLogin() {
      this.$refs.form.validate(valid => {
        if (valid) {
          // 调用登录API
          console.log('登录信息:', this.form);
          // 登录成功后跳转到管理首页
          uni.navigateTo({
            url: '/pages/admin/index'
          });
        }
      });
    }
  }
}
</script>

<style scoped>
.login-container {
  height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
  background-color: #f5f7fa;
}
.login-form {
  width: 350px;
  padding: 30px;
  background: #fff;
  border-radius: 5px;
  box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
}
.title {
  margin-bottom: 30px;
  text-align: center;
  color: #333;
}
.login-btn {
  width: 100%;
}
</style>